import React, { Component } from "react";
import { Button, Checkbox, Spin, message } from "antd";
import { messages } from "share/common";
import HotelServer from "../hotel-server";

class SetNotice extends Component {
  constructor(props) {
    super(props);
    this.state = {
      loading: false,
      hotelData: {}, // 酒店基础设置数据
      isOpen: false, // 是否启用
    };
  }

  componentWillMount() {
    this.initData();
  }

  initData = () => {
    HotelServer(this)
      .getPlatformModelData({ companyOid: this.props.companyOID })
      .then((res) => {
        this.setState({
          hotelData: res.data.body,
          isOpen: res.data.body.enabledSmsNotice || false,
        });
      });
  };

  onIsOpen = (eve) => {
    this.setState({ isOpen: eve.target.checked });
  };

  onSaveSetting = () => {
    const { hotelData, isOpen } = this.state;
    const params = Object.assign({}, hotelData);
    params.companyOid = this.props.companyOID;
    params.enabledSmsNotice = isOpen;
    HotelServer(this)
      .savePlatformModelData(params)
      .then((res) => {
        if (res.data.success) {
          message.success(messages("supplier-1.key355") /*保存成功*/);
          this.initData();
        } else {
          message.error(res.data.message);
        }
      });
  };

  render() {
    const { loading, isOpen } = this.state;
    return (
      <div className="airline-config-container">
        <Spin spinning={loading}>
          <h2>{messages("supplier-1.key377") /*短信通知*/}</h2>
          <a className="a-line-bottom">
            {
              messages(
                "supplier-1.key378"
              ) /*汇联易与机票服务商都会给你的员工发送短信，若不需要，可以取消汇联易的短信消息通知*/
            }
          </a>
          <Checkbox checked={isOpen} onChange={this.onIsOpen}>
            {messages("supplier-1.key35") /*启用temp*/}
          </Checkbox>
          <br />
          <br />
          <br />
          <br />
          <Button type="primary" onClick={this.onSaveSetting}>
            {messages("supplier-1.key356") /*保存配置*/}
          </Button>
        </Spin>
      </div>
    );
  }
}

export default SetNotice;
